﻿namespace ETestIT.UI
{
    using System;
    using System.Web;
    using Core.DataInterfaces;
    using Core.Infrastructure;
    using Presentation;

    public partial class Login : PageBase<Login>
    {
        readonly IUserRepository userRepository = IoC.Resolve<IUserRepository>();

#if DEBUG
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            PerformLogin("admin", "admin");
        }
#endif 

        protected void btnLogin_Clicked(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbName.Text))
                PerformLogin(tbName.Text, tbPassword.Text);
        }

        private void PerformLogin(string userName, string password)
        {
            if (userRepository.LogIn(userName, password) != null)
                HttpContext.Current.Response.Redirect("/Positions.aspx");
        }
    }
}